introduce thread_alive_p macro
authorTom Tromey <tromey@redhat.com>
Wed, 3 Jul 2013 22:20:07 +0000 (16:20 -0600)
committerTom Tromey <tromey@redhat.com>
Wed, 3 Jul 2013 22:20:07 +0000 (16:20 -0600)
This introduces the thread_alive_p macro and changes
thread-alive-p to use it.  This is a minor cleanup.
It also changes all-threads to ignore dead threads.

src/thread.c

index 0235944ccdc32c7f1debbd7291583de2b2206174..361968489c66450eff90e779d83b2f332b588388 100644 (file)
@@ -37,6 +37,12 @@ Lisp_Object Qthreadp, Qmutexp, Qcondition_variablep;
 
 \f
 
+/* m_specpdl is set when the thread is created and cleared when the
+   thread dies.  */
+#define thread_alive_p(STATE) ((STATE)->m_specpdl != NULL)
+
+\f
+
 static void
 release_global_lock (void)
 {
@@ -796,9 +802,7 @@ DEFUN ("thread-alive-p", Fthread_alive_p, Sthread_alive_p, 1, 1, 0,
   CHECK_THREAD (thread);
   tstate = XTHREAD (thread);
 
-  /* m_specpdl is set when the thread is created and cleared when the
-     thread dies.  */
-  return tstate->m_specpdl == NULL ? Qnil : Qt;
+  return thread_alive_p (tstate) ? Qt : Qnil;
 }
 
 DEFUN ("thread-blocker", Fthread_blocker, Sthread_blocker, 1, 1, 0,
@@ -865,10 +869,13 @@ DEFUN ("all-threads", Fall_threads, Sall_threads, 0, 0, 0,
 
   for (iter = all_threads; iter; iter = iter->next_thread)
     {
-      Lisp_Object thread;
+      if (thread_alive_p (iter))
+       {
+         Lisp_Object thread;
 
-      XSETTHREAD (thread, iter);
-      result = Fcons (thread, result);
+         XSETTHREAD (thread, iter);
+         result = Fcons (thread, result);
+       }
     }
 
   return result;